#include "bmp.h"
#include "tlg.h"
#include "stb_image.h"
unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len);

typedef struct {
    char name[NAMELEN], *path;
    int id, w, h, esiz;
    uint32_t *data;
    uint8_t *extra;
} sprite_sheet_t;
extern sprite_sheet_t *sheets;
extern int numsheets;

int sprites_detect(uint8_t *buf);
uint32_t *sprites_decode(uint8_t *buf, uint64_t size, int *w, int *h);
uint8_t *sprites_encode(int sprite, uint64_t *size);

void sprites_free(void);
int sprites_addsheet(int id, char *name, uint8_t *buf, uint32_t size);
int sprites_newsheet(int id, char *name, int w, int h);
void sprites_scansheets(void);

typedef struct {
    int dx, dy, s, x, y, w, h, dur, sfx;
} sprite_frame_t;

typedef struct {
    char name[NAMELEN];
    int id, w, h, numframe;
    sprite_frame_t *frame;
    uint32_t preview[64 * 64];
} sprite_t;
extern sprite_t *sprites;
extern int numsprites;

int sprites_add(int id, char *name, int w, int h, int dx, int dy, int sheet, int sx, int sy, int sw, int sh, int dur, int sfx);
void sprites_draw(int sprite, int frame, uint32_t *buf, int w, int h, int p, int x, int y, int scale);

void sprites_update(void);
void sprites_select(int idx);
void sprites_ctrl(void);
void sprites_view(void);
